package com.kelvin.oocl.operator.impl;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

import com.kelvin.oocl.db.DBData;
import com.kelvin.oocl.operator.CustomerOperator;
import com.kelvin.oocl.pojo.Customer;

public class CustomerOpetatorImpl implements CustomerOperator{
	private static Map<String, Customer> customers = DBData.assessData();

	@Override
	public boolean add(Customer customer) {
		if(null==customer){
			return false;
		}
		customers.put(customer.getId(), customer);
		return true;
	}

	@Override
	public boolean addAll(List<Customer> customers) {
		if(customers==null || customers.size()==0){
			return false;
		}
		for (Customer customer : customers) {
			CustomerOpetatorImpl.customers.put(customer.getId(), customer);
		}
		return true;
	}

	@Override
	public TreeSet<Customer> sort(Comparator<Customer> comparator) {
		if(null==comparator){
			return null;
		}
		TreeSet<Customer> set = new TreeSet<>(comparator);
		for(String id:customers.keySet()){
			set.add(customers.get(id));
		}
		return set;
	}

}
